<template>
  <el-dialog title="数据导入" :visible.sync="showCreateDataImportDialog" width="800px"
             @closed="handleClose" :destroy-on-close="true" :lock-scroll="false">

    <div class="el-dialog-div">

      <el-form ref="form" :model="CreateDataImportForm" label-width="100px" :rules="CreateDataImportFormRules">
        <el-form-item label="文件名" prop="excelFileName">
          <el-col :span="19">
            <el-upload
                class="upload-demo"
                drag
                action="https://jsonplaceholder.typicode.com/posts/"
                multiple
                v-model="CreateDataImportForm.excelFileName"
            >
              <i class="el-icon-upload"></i>
              <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
            </el-upload>
          </el-col>
          <el-col :span="5">
            <el-button size="small">？模板下载</el-button>
          </el-col>

        </el-form-item>

        <el-form-item label="图片路径" prop="photoFileName">
          <el-upload
              class="upload-demo"
              drag
              action="https://jsonplaceholder.typicode.com/posts/"
              multiple
              v-model="CreateDataImportForm.photoFileName"
          >
            <i class="el-icon-upload"></i>
            <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          </el-upload>
        </el-form-item>

        <el-alert title="导入说明：" type="info" :closable="false">
          <template>
            <div class="iconSize">1、导入文件支持excel 2007及以上版本xsl、xlsx格式的文件</div>
            <div class="iconSize">2、图片导入支持压缩包zip格式导入，单批次导入大小不超过500M，图片格式支持 bmp/jpg/jpeg/png</div>
            <div class="iconSize">3、人脸照片需按照人脸采集要求采集导入</div>
            <div class="iconSize">4、可只导入文件，人脸照片后续采集添加</div>
          </template>
        </el-alert>

      </el-form>

    </div >

    <div slot="footer">
      <el-button @click="showCreateDataImportDialog=false">取消</el-button>
      <el-button type="primary" @click="save">保存</el-button>
    </div>

  </el-dialog>
</template>

<script>
export default {
  name: "CreateDataImport",
  data() {
    return {
      CreateDataImportForm: {},  // 表单数据
      CreateDataImportFormRules: {  // 表单验证规则
        excelFileName: [
          {required: true, message: '请上传excel文件', trigger: 'blur'}
        ],
      },
      showCreateDataImportDialog: this.showCreateDataImportForm // 子组件不能直接修改父组件prop参数
    };
  },
  props: {
    showCreateDataImportForm: {
      type: Boolean,
      default() {
        return false;
      }
    },
  },
  computed: {
  },
  mounted() {
  },
  methods: {
    /* 保存编辑 */
    save() {
      this.$refs['createGradeForm'].validate((valid) => {
        if (valid) {
          const loading = this.$loading({lock: true});
          this.$http.post('/grade/edit', this.createStudentForm).then(res => {
            loading.close();
            if (res.data.code === 200) {
              this.$message({type: 'success', message: res.data.msg});
              this.$emit('reload')
            } else {
              this.$message.error(res.data.msg);
            }
          }).catch(e => {
            loading.close();
            this.$message.error(e.message);
          });
        } else {
          return false;
        }
      });
    },
    /**
     * 关闭页面
     */
    handleClose(hide) {
      if (hide) {
        hide();
      }
      this.CreateDataImportForm={} // 清空表单数据
      this.$emit('update:showCreateDataImportForm', false)
    },
  },
  watch: {
    showCreateDataImportForm(val) { // 监听该值的变化
      this.showCreateDataImportDialog = val;
    }
  }
};
</script>


<style scoped>
.upload-demo >>> .el-upload-dragger {
    width: 500px;
    height: 35px;
}

.upload-demo >>> .el-icon-upload {
  margin: 0;
  font-size: 26px;
  line-height: 30px;
}

.upload-demo .el-upload__text {
  font-size: 15px;
  display: inline-block;
}


</style>